#include<iostream>
using namespace std;
int main(){
    int q;
    char a,b;
    string s;
    cin>>s>>q;
    while(q--){
        cin>>a>>b;
        for(int i=0;i<s.length();i++)
            if(s[i]==a)
                s[i]=b;
    }
    cout<<s<<endl;
    return 0;
}